<?php


namespace Zyan\SitemapOutput\Format;


class Xml implements FormatInterface
{
    protected $item = [];
    public function write($url, $lastmod, $changefreq = 'daily', $priority = '0.8', $mobile = 'pc,mobile')
    {
        $this->item[] = "<url>
                            <loc>{$url}</loc>
                            <lastmod>{$lastmod}</lastmod>
                            <changefreq>{$changefreq}</changefreq>
                            <priority>{$priority}</priority>
                            <mobile:mobile type=\"{$mobile}\"/>
                        </url>";
    }

    public function getContents()
    {
        $contents = '<?xml version="1.0" encoding="utf-8"?>';
        $contents .= '<urlset>';
        $contents .= join("\n",$this->item);
        $contents .= '</urlset>';
        $this->item = [];
        return $contents;
    }
}